package com.scvtc.service.dictionary.impl;

import cn.hutool.core.map.MapUtil;
import com.scvtc.domain.ForeignKeyCache;
import com.scvtc.domain.ResResult;
import com.scvtc.service.dictionary.DictionaryService;
import com.scvtc.utils.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static com.scvtc.constants.RedisConstant.STUDENT_BASE;
import static com.scvtc.constants.RedisConstant.TEACHER_BASE;

/**
 * @Description: 字典服务层
 * @Author: yiFei
 * @date: 2022/5/13 11:55
 */
@Service("dictionaryService")
public class DictionaryServiceImpl implements DictionaryService {

    @Autowired
    private RedisUtil redisUtil;

    /**
     * 表单中下拉和选择选项
     *
     * @return
     */
    @Override
    public ResResult<Map<String, List<String>>> form() {
        return ResResult.noMsgSuccess(
                MapUtil.builder(new HashMap<String, List<String>>())
                        .put("political", political())
                        .put("student_way", studentWay())
                        .put("student_status", studentStatus())
                        .put("student_status_category", studentStatusCategory())
                        .put("student_only_child", studentOnlyChild())
                        .put("student_is_loan", stuIsLoan())
                        .put("teacher_retired", teacherRetired())
                        .put("teacher_situation", teacherSituation())
                        .put("awards_level", awardsLevel())
                        .build()
        );
    }

    /**
     * 学生基本信息
     *
     * @param studentName
     * @return
     */
    @Override
    public ResResult<List<ForeignKeyCache>> studentBase(String studentName) {
        // 过滤
        List<ForeignKeyCache> studentRecommend = redisUtil.getCacheList(STUDENT_BASE);
        if (StringUtils.hasText(studentName)) {
            studentRecommend = studentRecommend.stream()
                    .distinct()
                    .filter(item -> item.getValue().contains(studentName))
                    .collect(Collectors.toList());
        }
        // 无消息返回
        return ResResult.noMsgSuccess(studentRecommend);
    }

    /**
     * 教师基本信息
     *
     * @param teacherName
     * @return
     */
    @Override
    public ResResult<List<ForeignKeyCache>> teacherBase(String teacherName) {
        // 过滤
        List<ForeignKeyCache> teacherRecommend = redisUtil.getCacheList(TEACHER_BASE);
        if (StringUtils.hasText(teacherName)) {
            teacherRecommend = teacherRecommend.stream()
                    .distinct()
                    .filter(item -> item.getValue().contains(teacherName))
                    .collect(Collectors.toList());
        }
        // 无消息返回
        return ResResult.noMsgSuccess(teacherRecommend);
    }


    /**
     * 教师在职状态
     * 在职,退职
     *
     * @return
     */
    private List<String> teacherRetired() {
        List<String> teacher_retired = new ArrayList<>();
        teacher_retired.add("退休");
        teacher_retired.add("在职");
        return teacher_retired;
    }

    /**
     * 教师在职状态
     * '编内','编外','临时'
     *
     * @return
     */
    private List<String> teacherSituation() {
        List<String> teacher_situation = new ArrayList<>();
        teacher_situation.add("编内");
        teacher_situation.add("编外");
        teacher_situation.add("临时");
        return teacher_situation;
    }

    /**
     * 是否贷款
     *
     * @return
     */
    private List<String> stuIsLoan() {
        List<String> stu_is_loan = new ArrayList<>();
        stu_is_loan.add("是");
        stu_is_loan.add("否");
        return stu_is_loan;
    }

    /**
     * 是否为独生子女
     *
     * @return
     */
    private List<String> studentOnlyChild() {
        List<String> student_only_child = new ArrayList<>();
        student_only_child.add("是");
        student_only_child.add("否");
        return student_only_child;
    }

    /**
     * 学籍状态
     * '正常','升级','跳级','留降级（重修）','转入','转出','转专业','专升本','本转专','复学','考研','其他'
     *
     * @return
     */
    private List<String> studentStatusCategory() {
        List<String> statusCategory = new ArrayList<>();
        statusCategory.add("正常");
        statusCategory.add("升级");
        statusCategory.add("留降级（重修）");
        statusCategory.add("转入");
        statusCategory.add("转出");
        statusCategory.add("转专业");
        statusCategory.add("专升本");
        statusCategory.add("本转专");
        statusCategory.add("复学");
        statusCategory.add("考研");
        statusCategory.add("其他");
        return statusCategory;
    }

    /**
     * 学籍状态
     * '注册学籍','暂缓注册','退学','休学','毕业','其他'
     *
     * @return
     */
    private List<String> studentStatus() {
        List<String> status = new ArrayList<>();
        status.add("注册学籍");
        status.add("暂缓注册");
        status.add("退学");
        status.add("休学");
        status.add("毕业");
        status.add("其他");
        return status;
    }

    /**
     * 学生入学方式
     *
     * @return
     */
    private List<String> studentWay() {
        List<String> way = new ArrayList<>();
        way.add("统招");
        way.add("对口入学");
        way.add("保送");
        way.add("艺体特招");
        way.add("外校转入");
        way.add("复学");
        way.add("其他");
        return way;
    }

    /**
     * 学生政治面貌
     *
     * @return
     */
    private List<String> political() {
        List<String> political = new ArrayList<>();
        political.add("中共党员");
        political.add("中共预备党员");
        political.add("共青团员");
        political.add("民革会员");
        political.add("民盟盟员");
        political.add("民建会员");
        political.add("民进会员");
        political.add("农工党党员");
        political.add("致公党党员");
        political.add("九三学社社员");
        political.add("台盟盟员");
        political.add("无党派民主人士");
        political.add("群众");
        return political;
    }

    /**
     * 获奖级别（省赛还是国赛）
     *
     * @return
     */
    private List<String> awardsLevel() {
        List<String> awards_level = new ArrayList<>();
        awards_level.add("省级");
        awards_level.add("国家级");
        return awards_level;
    }

}
